import requests

# get请求——参数设定
# url = "http://www.baidu.com"
# # data = {"id": 1001}
# # data = {"id": "1001, 1002"}
# data = {"id": 1001, "wd": "北京"}
# r = requests.get(url, data)
# print(r.url)
# print(r.status_code)
# print(r.text)

# post请求 tpshop表单数据，利用cookie进行登陆
head = {"Content-type": "application/x-www-form-urlencoded"}
data = {
    "username": "13800138006",
    "password": "123456",
    "verify_code": "8888"
}
url = "http://localhost/index.php?m=Home&c=User&a=do_login"
r = requests.post(url, data=data, headers=head)
print(r.url)
print(r.status_code)
print(r.text)
print(r.json())

# post请求 ihrm json数据
# head_json = {"Content-type": "application/json"}
# data_json = {
#     "mobile": "13800000002",
#     "password": "888itcast.CN764%..."
# }
# url = "http://ihrm-java.itheima.net/api/sys/login"
# r = requests.post(url, json=data_json, headers=head_json)
# print(r.url)
# print(r.status_code)
# print(r.text)
# print(r.json())

# 响应内容详解
# r = requests.get("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png")
# # 保存请求到的图片
# with open("E://download/1.png", "wb") as f:
#     f.write(r.content)
# print(r.content)
# print(r.headers)
# # 解决乱码问题
# print(r.encoding)
# r.encoding = "UTF-8"
# # 获取cookie
# print(r.cookies["BAIDUID"])


